package com.example.teaching_server.controller;

import com.example.teaching_server.common.ApiResponse;
import com.example.teaching_server.entity.ExtracurricularRecording;
import com.example.teaching_server.service.ExtracurricularRecordingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/extracurricular-recordings")
@RequiredArgsConstructor
@Tag(name = "课外课程实录管理", description = "课外课程实录查询和管理接口")
public class ExtracurricularRecordingController {

    private final ExtracurricularRecordingService recordingService;

    @GetMapping
    @Operation(summary = "获取课外课程实录列表", description = "根据学期ID和班级ID查询课外课程实录信息")
    public ApiResponse<List<ExtracurricularRecording>> getRecordings(
            @Parameter(description = "学期ID")
            @RequestParam(required = false) Integer termId,

            @Parameter(description = "班级ID")
            @RequestParam(required = false) Integer classId) {

        log.info("接收到课外课程实录查询请求: termId={}, classId={}", termId, classId);

        try {
            List<ExtracurricularRecording> recordings = recordingService.getRecordingsByCriteria(termId, classId);
            log.info("成功查询到{}条课外课程实录记录", recordings.size());
            return ApiResponse.success("课外课程实录获取成功", recordings);
        } catch (Exception e) {
            log.error("查询课外课程实录失败", e);
            return ApiResponse.fail("获取课外课程实录失败: " + e.getMessage());
        }
    }
}
